const Service = require('egg').Service;
const fs = require('mz/fs');
const pump = require('mz-modules/pump');
const uuid = require('uuid/v1');
const path = require("path")
class UploadService extends Service {
    async uploadfile() {
        const ctx = this.ctx;
        
        const stream = await ctx.getFileStream();
        const file = stream;

        const filename = file.filename.toLowerCase();
        //console.log(this.config.baseDir);
        const uuidName = uuid() + filename
        const targetPath = path.join(this.config.baseDir, 'app/public/img/', uuidName);
        const target = fs.createWriteStream(targetPath);
        console.log('3');
        console.log(stream);
        await pump(stream, target);
        console.log('4');
        const uil = path.join('/public/img/', uuidName);
        return  {imgUil : uil}
    }



}
module.exports = UploadService